{% extends 'base.html' %}
{% load static %}

{% block title %}积分历史 - 活动社交平台{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="row">
        <div class="col-12">
            <div class="d-flex justify-content-between align-items-center mb-4">
                <h4>积分历史</h4>
                <a href="{% url 'points_mall' %}" class="btn btn-outline-primary">
                    <i class="fas fa-arrow-left"></i> 返回商城
                </a>
            </div>
            
            <!-- 积分概览 -->
            <div class="card mb-4">
                <div class="card-body">
                    <div class="row text-center">
                        <div class="col-md-4">
                            <div class="stat-item">
                                <div class="stat-number text-primary">{{ user_points.total_points }}</div>
                                <div class="stat-label">总积分</div>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="stat-item">
                                <div class="stat-number text-success">{{ user_points.available_points }}</div>
                                <div class="stat-label">可用积分</div>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="stat-item">
                                <div class="stat-number text-info">{{ page_obj.paginator.count }}</div>
                                <div class="stat-label">积分记录</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 积分记录列表 -->
            <div class="card">
                <div class="card-body">
                    {% if page_obj %}
                    <div class="table-responsive">
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th>时间</th>
                                    <th>积分变化</th>
                                    <th>来源</th>
                                    <th>描述</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for record in page_obj %}
                                <tr>
                                    <td>{{ record.created_at|date:"Y-m-d H:i" }}</td>
                                    <td>
                                        <span class="{% if record.points > 0 %}text-success{% else %}text-danger{% endif %}">
                                            {% if record.points > 0 %}+{% endif %}{{ record.points }}
                                        </span>
                                    </td>
                                    <td>
                                        <span class="badge bg-{% if record.points > 0 %}success{% else %}warning{% endif %}">
                                            {{ record.get_source_type_display }}
                                        </span>
                                    </td>
                                    <td>{{ record.description }}</td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                    
                    <!-- 分页 -->
                    {% if page_obj.has_other_pages %}
                    <nav aria-label="Page navigation" class="mt-4">
                        <ul class="pagination justify-content-center">
                            {% if page_obj.has_previous %}
                            <li class="page-item">
                                <a class="page-link" href="?page={{ page_obj.previous_page_number }}">上一页</a>
                            </li>
                            {% endif %}
                            
                            {% for num in page_obj.paginator.page_range %}
                                {% if page_obj.number == num %}
                                <li class="page-item active">
                                    <span class="page-link">{{ num }}</span>
                                </li>
                                {% else %}
                                <li class="page-item">
                                    <a class="page-link" href="?page={{ num }}">{{ num }}</a>
                                </li>
                                {% endif %}
                            {% endfor %}
                            
                            {% if page_obj.has_next %}
                            <li class="page-item">
                                <a class="page-link" href="?page={{ page_obj.next_page_number }}">下一页</a>
                            </li>
                            {% endif %}
                        </ul>
                    </nav>
                    {% endif %}
                    
                    {% else %}
                    <div class="text-center py-5">
                        <i class="fas fa-history fa-3x text-muted mb-3"></i>
                        <p class="text-muted">暂无积分记录</p>
                        <a href="/meet/active/" class="btn btn-primary">去参加活动赚积分</a>
                    </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_css %}
<style>
.stat-item {
    padding: 15px 0;
}

.stat-number {
    font-size: 2rem;
    font-weight: bold;
    margin-bottom: 5px;
}

.stat-label {
    color: #6c757d;
    font-size: 0.9rem;
}
</style>
{% endblock %}